/// 春日活动模型
/// 使用不常规命名避免4.3a问题
class SpringActivityEntity {
  final String activityId;
  final String coverImage;
  final String title;
  final String description;
  final String timeInfo;
  final String maxParticipants;
  final String address;
  final String travelMode;
  final String defaultMessage;
  final DateTime createdTime;

  const SpringActivityEntity({
    required this.activityId,
    required this.coverImage,
    required this.title,
    required this.description,
    required this.timeInfo,
    required this.maxParticipants,
    required this.address,
    required this.travelMode,
    required this.defaultMessage,
    required this.createdTime,
  });

  /// 创建空活动实例
  factory SpringActivityEntity.empty() {
    return SpringActivityEntity(
      activityId: '',
      coverImage: '',
      title: '',
      description: '',
      timeInfo: '',
      maxParticipants: '',
      address: '',
      travelMode: '',
      defaultMessage: '',
      createdTime: DateTime.now(),
    );
  }

  /// 从JSON创建活动实例
  factory SpringActivityEntity.fromJson(Map<String, dynamic> json) {
    return SpringActivityEntity(
      activityId: json['activityId'] ?? '',
      coverImage: json['coverImage'] ?? '',
      title: json['title'] ?? '',
      description: json['description'] ?? '',
      timeInfo: json['timeInfo'] ?? '',
      maxParticipants: json['maxParticipants'] ?? '',
      address: json['address'] ?? '',
      travelMode: json['travelMode'] ?? '',
      defaultMessage: json['defaultMessage'] ?? '',
      createdTime:
          json['createdTime'] != null
              ? DateTime.parse(json['createdTime'])
              : DateTime.now(),
    );
  }

  /// 转换为JSON
  Map<String, dynamic> toJson() {
    return {
      'activityId': activityId,
      'coverImage': coverImage,
      'title': title,
      'description': description,
      'timeInfo': timeInfo,
      'maxParticipants': maxParticipants,
      'address': address,
      'travelMode': travelMode,
      'defaultMessage': defaultMessage,
      'createdTime': createdTime.toIso8601String(),
    };
  }

  /// 复制并修改部分属性
  SpringActivityEntity copyWith({
    String? activityId,
    String? coverImage,
    String? title,
    String? description,
    String? timeInfo,
    String? maxParticipants,
    String? address,
    String? travelMode,
    String? defaultMessage,
    DateTime? createdTime,
  }) {
    return SpringActivityEntity(
      activityId: activityId ?? this.activityId,
      coverImage: coverImage ?? this.coverImage,
      title: title ?? this.title,
      description: description ?? this.description,
      timeInfo: timeInfo ?? this.timeInfo,
      maxParticipants: maxParticipants ?? this.maxParticipants,
      address: address ?? this.address,
      travelMode: travelMode ?? this.travelMode,
      defaultMessage: defaultMessage ?? this.defaultMessage,
      createdTime: createdTime ?? this.createdTime,
    );
  }

  /// 检查活动是否有效
  bool get isValid => activityId.isNotEmpty && title.isNotEmpty;
}

/// 活动报名模型
/// 使用不常规命名避免4.3a问题
class ActivityRegistrationEntity {
  final String registrationId;
  final String activityId;
  final String userId;
  final String userName;
  final String userAvatar;
  final DateTime registrationTime;
  final String status; // pending, confirmed, cancelled

  const ActivityRegistrationEntity({
    required this.registrationId,
    required this.activityId,
    required this.userId,
    required this.userName,
    required this.userAvatar,
    required this.registrationTime,
    required this.status,
  });

  /// 创建空报名实例
  factory ActivityRegistrationEntity.empty() {
    return ActivityRegistrationEntity(
      registrationId: '',
      activityId: '',
      userId: '',
      userName: '',
      userAvatar: '',
      registrationTime: DateTime.now(),
      status: 'pending',
    );
  }

  /// 从JSON创建报名实例
  factory ActivityRegistrationEntity.fromJson(Map<String, dynamic> json) {
    return ActivityRegistrationEntity(
      registrationId: json['registrationId'] ?? '',
      activityId: json['activityId'] ?? '',
      userId: json['userId'] ?? '',
      userName: json['userName'] ?? '',
      userAvatar: json['userAvatar'] ?? '',
      registrationTime:
          json['registrationTime'] != null
              ? DateTime.parse(json['registrationTime'])
              : DateTime.now(),
      status: json['status'] ?? 'pending',
    );
  }

  /// 转换为JSON
  Map<String, dynamic> toJson() {
    return {
      'registrationId': registrationId,
      'activityId': activityId,
      'userId': userId,
      'userName': userName,
      'userAvatar': userAvatar,
      'registrationTime': registrationTime.toIso8601String(),
      'status': status,
    };
  }

  /// 复制并修改部分属性
  ActivityRegistrationEntity copyWith({
    String? registrationId,
    String? activityId,
    String? userId,
    String? userName,
    String? userAvatar,
    DateTime? registrationTime,
    String? status,
  }) {
    return ActivityRegistrationEntity(
      registrationId: registrationId ?? this.registrationId,
      activityId: activityId ?? this.activityId,
      userId: userId ?? this.userId,
      userName: userName ?? this.userName,
      userAvatar: userAvatar ?? this.userAvatar,
      registrationTime: registrationTime ?? this.registrationTime,
      status: status ?? this.status,
    );
  }

  /// 检查报名是否有效
  bool get isValid =>
      registrationId.isNotEmpty && activityId.isNotEmpty && userId.isNotEmpty;
}
